home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / src / XTCL_getfile.c < prev    next >
Text File  |  1993-11-18  |  3KB  |  106 lines

  1. /*
  2. ** This source code was written by Tim Endres
  3. ** Email: time@ice.com.
  4. ** USMail: 8840 Main Street, Whitmore Lake, MI  48189
  5. **
  6. ** Some portions of this application utilize sources
  7. ** that are copyrighted by ICE Engineering, Inc., and
  8. ** ICE Engineering retains all rights to those sources.
  9. **
  10. ** Neither ICE Engineering, Inc., nor Tim Endres, 
  11. ** warrants this source code for any reason, and neither
  12. ** party assumes any responsbility for the use of these
  13. ** sources, libraries, or applications. The user of these
  14. ** sources and binaries assumes all responsbilities for
  15. ** any resulting consequences.
  16. */
  17.  
  18. #include <Types.h>
  19. #include <Resources.h>
  20. #include <QuickDraw.h>
  21. #include <Windows.h>
  22. #include <Memory.h>
  23. #include <Files.h>
  24. #include "tcl.h"
  25. #include "xtcl.h"
  26.  
  27. #define sprintf        sprintf_drvr
  28. #define FALSE        (Boolean)0
  29.  
  30. void
  31. XTCLEntry(argc, argv, xpb)
  32. int            argc;
  33. char        **argv;
  34. XTCLParmBlk    *xpb;
  35. {
  36. char    buffer1[64];
  37. char    buffer2[64];
  38. char    buffer3[64];
  39. char    buffer4[64];
  40. char    pascal_name[256];
  41. Handle    resultH;
  42. DateTimeRec    cdate, mdate;
  43. ParamBlockRec    pb;
  44. #pragma unused (argc)
  45.  
  46.     resultH = xpb->resultH;
  47.     
  48.     strcpy(pascal_name, argv[1]);
  49.     c2pstr(pascal_name);
  50.     
  51.     pb.fileParam.ioCompletion = 0;
  52.     pb.fileParam.ioVRefNum = 0;
  53.     pb.fileParam.ioNamePtr = pascal_name;
  54.     pb.fileParam.ioFDirIndex = 0;
  55.     pb.fileParam.ioFVersNum = 0;
  56.     PBGetFInfo(&pb, FALSE);
  57.     if (pb.fileParam.ioResult != noErr) {
  58.         sprintf(buffer1, "error #%d retrieving info for '%.32s'.",
  59.                     pb.fileParam.ioResult, argv[1]);
  60.         SetHandleSize(resultH, strlen(buffer1) + 1);
  61.         if (MemError() == noErr)
  62.             strcpy(*resultH, buffer1);
  63.         xpb->result = TCL_ERROR;
  64.         }
  65.     else {
  66.         Secs2Date(pb.fileParam.ioFlCrDat, &cdate);
  67.         Secs2Date(pb.fileParam.ioFlMdDat, &mdate);
  68.         sprintf(buffer1, "'%4.4s' '%4.4s' %c%c%c%c%c%c%c",
  69.                     &pb.fileParam.ioFlFndrInfo.fdCreator, &pb.fileParam.ioFlFndrInfo.fdType,
  70.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&0x8000)!=0)        ? 'L' : 'l' ),
  71.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&fInvisible)!=0)    ? 'V' : 'v' ),
  72.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&fHasBundle)!=0)    ? 'B' : 'b' ),
  73.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&0x1000)!=0)        ? 'S' : 's' ),
  74.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&0x0100)!=0)        ? 'I' : 'i' ),
  75.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&fOnDesk)!=0)        ? 'D' : 'd' ),
  76.                     ( ((pb.fileParam.ioFlFndrInfo.fdFlags&0x0080)!=0)        ? 'M' : 'm' )                    
  77.                     );
  78.         sprintf(buffer2, "%02d/%02d/%02d %02d:%02d:%02d",
  79.                     cdate.month, cdate.day, cdate.year%100, cdate.hour, cdate.minute, cdate.second
  80.                     );
  81.         sprintf(buffer3, "%02d/%02d/%02d %02d:%02d:%02d",
  82.                     mdate.month, mdate.day, mdate.year%100, mdate.hour, mdate.minute, mdate.second
  83.                     );
  84.         sprintf(buffer4, "%d,%d %ld %ld",
  85.                     pb.fileParam.ioFlFndrInfo.fdLocation.h,
  86.                     pb.fileParam.ioFlFndrInfo.fdLocation.v,
  87.                     pb.fileParam.ioFlLgLen, pb.fileParam.ioFlRLgLen
  88.                     );
  89.         SetHandleSize(resultH,
  90.                         (strlen(buffer1) + strlen(buffer2) +
  91.                          strlen(buffer3) + strlen(buffer4) + 2) );
  92.         if (MemError() == noErr) {
  93.             sprintf(*resultH, "%s %s %s %s", buffer1, buffer2, buffer3, buffer4);
  94.             xpb->result = TCL_OK;
  95.             }
  96.         else {
  97.             sprintf(buffer1, "not enough memory for result");
  98.             SetHandleSize(resultH, strlen(buffer1) + 1);
  99.             if (MemError() == noErr)
  100.                 strcpy(*resultH, buffer1);
  101.             xpb->result = TCL_ERROR;
  102.             }
  103.         }
  104.     }
  105.  
  106.